package com.hy.ssm.util;

import java.util.Map;

/**
 * @Auther: HuYang
 * @Date: 2022/11/6 - 11 - 06 - 11:42
 * @Description: com.yc.snack.util
 * @version: 1.0
 */
public class StringUtil {
    /**
     * 判空方法
     * @param strs
     * @return
     */
    public static boolean checkNull(String ... strs) {
        if(strs == null || strs.length <= 0) {
            return true;
        }

        for(String str : strs) {
            if(str == null || "".equals(str)) {
                return true;
            }
        }
        return false;
    }
    /**
     * 判空方法
     * @param objs
     * @return
     */
    public static boolean checkNull(Object ... objs) {
        if(objs == null || objs.length <= 0) {
            return true;
        }

        for(Object obj : objs) {
            if(obj == null || "".equals(String.valueOf(obj))) {
                return true;
            }
        }
        return false;
    }

    public static Map<String,Object> findByPageUtil(Map<String,Object> map){
        int page = 1;
        Object temp = map.get("page");
        if (temp != null && !"".equals(String.valueOf(temp))){
            page = Integer.parseInt(String.valueOf(temp));
        }

        int rows = 10;
        temp = map.get("rows");
        if (temp != null && !"".equals(String.valueOf(temp))){
            rows = Integer.parseInt(String.valueOf(temp));
        }

        map.put("page",(page -1 ) * rows);
        map.put("rows",rows);
        System.out.println(map);
        return map;
    }

    public static Map<String, Object> findByPageTable(Map<String, Object> map) {
        int page = 1;
        Object temp = map.get("page");
        if(temp != null && !"".equals(String.valueOf(temp))) {
            page = Integer.parseInt(String.valueOf(temp));
        }

        int rows = 10;
        temp = map.get("limit");
        if(temp != null && !"".equals(String.valueOf(temp))) {
            rows = Integer.parseInt(String.valueOf(temp));
        }
        map.put("page", (page - 1) * rows);
        map.put("rows", rows);
        return map;
    }

}
